package com.ssm.zhihu_ssm.controller;

import com.ssm.zhihu_ssm.entity.Recommend;
import com.ssm.zhihu_ssm.service.RecommendService;
import com.ssm.zhihu_ssm.service.UserService;
import com.ssm.zhihu_ssm.util.ReturnMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class RecommendController {

    @Autowired
    private RecommendService recommendService;
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping("/getRecommend")//推荐
    public Map<String,Object> getRecommend(String phone){
        int x = userService.findId(phone);
        List<Recommend> recommendList = recommendService.getRecommend(x);
        Map<String,Object> map = ReturnMap.ReturnMapS(recommendList);
        return map;
    }

    @ResponseBody
    @RequestMapping("/getAllAnswerByQuestionId")//问题详情页
    public Map<String,Object> getRAllAnswerByQuestionId(int id){
        List<Recommend> recommendList = recommendService.getAllAnswerByQuestionId(id);
        Map<String,Object> map = ReturnMap.ReturnMapS(recommendList);
        return map;
    }

    @ResponseBody
    @RequestMapping("/getFollowAnswerByUserId")//推荐
    public Map<String,Object> getFollowAnswerByUserId(String phone){
        int x = userService.findId(phone);
        List<Recommend> recommendList = recommendService.getFollowAnswerByUserId(x);
        Map<String,Object> map = ReturnMap.ReturnMapS(recommendList);
        return map;
    }

    @ResponseBody
    @RequestMapping("/getCollectAnswerByUserId")//收藏的回答
    public Map<String,Object> getCollectAnswerByUserId(String phone){
        int x = userService.findId(phone);
        List<Recommend> recommendList = recommendService.getCollectAnswerByUserId(x);
        Map<String,Object> map = ReturnMap.ReturnMapS(recommendList);
        return map;
    }

    @ResponseBody
    @RequestMapping("/getAnswerByUserId")//收藏的回答
    public Map<String,Object> getAnswerByUserId(String phone){
        int x = userService.findId(phone);
        List<Recommend> recommendList = recommendService.getAnswerByUserId(x);
        Map<String,Object> map = ReturnMap.ReturnMapS(recommendList);
        return map;
    }
}